<?php
namespace frame\libs;

/**
 * 配置加载类
 */
class Config {

    public static $conf = array();

    /**
     * 获取当个配置项
     * @param  [type] $name [description]
     * @param  [type] $file [description]
     * @return [type]       [description]
     */
    public static function get($name, $file)
    {
        if (isset(self::$conf[$file][$name])) {
            return self::$conf[$file][$name];
        } else {
            if (isset($_GET['m']) && $_GET['m']) {
                $path = APP_PATH . $_GET['m'] . DS . 'config' . DS . $file . '.php';
                if (!is_file($path)) {
                    $path = ROOT_PATH . 'config' . DS . $file . '.php';
                }
            }else{
                $path = ROOT_PATH . 'config' . DS . $file . '.php';
            }
            if (is_file($path)) {
                $conf = include $path;
                if (isset($conf[$name])) {
                    self::$conf[$file] = $conf;
                    return $conf[$name];
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    } 

    /**
     * 获取所有配置项
     * @param  [type] $file [description]
     * @return [type]       [description]
     */
    public static function all($file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else {
            if (isset($_GET['m']) && $_GET['m']) {
                $path = APP_PATH . $_GET['m'] . DS . 'config' . DS . $file . '.php';
                if (!is_file($path)) {
                    $path = ROOT_PATH . 'config' . DS . $file . '.php';
                }
            }else{
                $path = ROOT_PATH . 'config' . DS . $file . '.php';
            }
            if (is_file($path)) {
                $conf = include $path;
                self::$conf[$file] = $conf;
                return $conf;
            } else {
                return false;
            }
        }
    }

}

